﻿using System;
using System.Collections.Generic;
using System.Text;

namespace unitlib
{
    /// <summary>
    /// 力学单位，千牛
    /// </summary>
    public readonly struct Unit_kN : IUnit
    {
        public double Value { get; }
        public string Unit => "kN";

        public string LatexUnit => "\\mathrm{kN}";

        public Unit_kN(double value) { Value = value; }
        public Unit_kN Round(int digits) => new Unit_kN(Math.Round(Value, digits));
        //数值与字符串转换
        public override string ToString() => Value.ToString();
        public static explicit operator Unit_kN(double value) => new Unit_kN(value);
        public static explicit operator double(Unit_kN value) => value.Value;
        public static implicit operator Unit_kN(string value) => new Unit_kN(value.Parse());
        public static implicit operator Unit_N(Unit_kN value) => new Unit_N(value.Value * 1000d);
        public static implicit operator Unit_kN(Unit_N value) => new Unit_kN(value.Value / 1000d);
        //比较运算
        public static bool operator ==(Unit_kN left, Unit_kN right) => left.Equals(right);
        public static bool operator !=(Unit_kN left, Unit_kN right) => !left.Equals(right);
        public override bool Equals(object obj) => obj is Unit_kN other && other.Value == Value;
        public override int GetHashCode()
        {
            unchecked
            {
                return GetType().GetHashCode() * 31 + Value.GetHashCode();
            }
        }
        //常规运算
        public static Unit_kN operator +(Unit_kN left, Unit_kN right) => new Unit_kN(left.Value + right.Value);
        public static Unit_kN operator -(Unit_kN left, Unit_kN right) => new Unit_kN(left.Value - right.Value);
        public static Unit_kN operator *(Unit_kN left, UnitValue right) => new Unit_kN(left.Value * right.Value);
        public static Unit_kN operator *(UnitValue left, Unit_kN right) => new Unit_kN(left.Value * right.Value);
        public static Unit_kN operator /(Unit_kN left, UnitValue right) => new Unit_kN(left.Value / right.Value);
        public static UnitValue operator /(Unit_kN left, Unit_kN right) => new UnitValue(left.Value / right.Value);
        //新增运算  
    }
}
